$(function () {

    $("#entry_btn").on('click', function () {
        var adminUsername = $('.username').val();
        var adminPassword = $('.password').val();
        if (adminUsername == '') {
            swal(
                '请输入用户名！',
                '请输入用户名后登录',
                'error'
            );
            $(this).parent().find('.username').focus();
            return false;
        } else if (adminPassword == '') {
            swal(
                '请输入密码！',
                '请输入密码后登录',
                'error'
            );
            $(this).parent().find('.password').focus();
            return false;
        }  else {
            $.ajax({
                type: "POST",
                url: base + "/auth/login",
                data: {
                    username: adminUsername,
                    password: adminPassword
                },
                success: function (msg) {
                    if (msg.resultCode == 0) {
                        window.location.href = '/first.html';
                        window.sessionStorage.setItem('username', msg.data.adminRealname);
                    } else {
                        swal(
                            '账号或密码错误！',
                            '请确认信息后登录',
                            'error'
                        );
                    }
                },
                err: function (err) {
                    swal(
                        err,
                        'error'
                    );
                }
            })
        }
    });
})




